<html><head><title>Joint.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - SliderJoint &amp; HingeJoint
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><b><font color="#3A3966">IncludeFile</font></b> <font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Screen3DRequester.pb&quot;

<b><font color="#3A3966">Define</font></b>.f KeyX, KeyY, MouseX, MouseY
<b><font color="#3A3966">Define</font></b> Direction = 0, Time =<font color="#3A3966"> ElapsedMilliseconds</font>()

<font color="#924B72">#CameraSpeed</font> = 1

<b><font color="#3A3966">Macro</font></b> <font color="#3A3966">DoorClosed</font>()
  (<font color="#3A3966">EntityX</font>(1) &gt; -1.07)  
<b><font color="#3A3966">EndMacro</font></b>

<b><font color="#3A3966">If</font></b> <font color="#3A3966">InitEngine3D</font>()
  
<font color="#3A3966">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Data/Textures&quot;, <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Data/Models&quot;, <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Data/Scripts&quot;, <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">  Parse3DScripts</font>()
  
<font color="#3A3966">  InitSprite</font>()
<font color="#3A3966">  InitKeyboard</font>()
<font color="#3A3966">  InitMouse</font>()
  
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">Screen3DRequester</font>()
    
    <font color="#3A3966">; First create materials
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    CreateMaterial</font>(0,<font color="#3A3966"> LoadTexture</font>(0, &quot;Dirt.jpg&quot;))
<font color="#3A3966">    CreateMaterial</font>(1,<font color="#3A3966"> LoadTexture</font>(1, &quot;Wood.jpg&quot;))
<font color="#3A3966">    GetScriptMaterial</font>(2, &quot;Color/Green&quot;)
<font color="#3A3966">    GetScriptMaterial</font>(3, &quot;Color/Red&quot;)  
    
    <font color="#3A3966">; Meshes
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    CreateCube</font>(0, 1.0)
<font color="#3A3966">    CreateSphere</font>(1, 0.5)
    
    <font color="#3A3966">; Entities
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    CreateEntity</font>(0,<font color="#3A3966"> MeshID</font>(0),<font color="#3A3966"> MaterialID</font>(0),  1, 0.1, 0)
<font color="#3A3966">    ScaleEntity</font>(0, 2, 4, 0.5)
<font color="#3A3966">    CreateEntity</font>(1,<font color="#3A3966"> MeshID</font>(0),<font color="#3A3966"> MaterialID</font>(1), -3, 0.1, 0)
<font color="#3A3966">    ScaleEntity</font>(1, 2, 4, 0.5)
    
<font color="#3A3966">    CreateEntity</font>(3,<font color="#3A3966"> MeshID</font>(1),<font color="#3A3966"> MaterialID</font>(3), -1, -1.25, 0.23)
    
<font color="#3A3966">    CreateEntity</font>(4,<font color="#3A3966"> MeshID</font>(0),<font color="#3A3966"> MaterialID</font>(0),  -2, -2.3, -1.0)
<font color="#3A3966">    ScaleEntity</font>(4, 8, 0.5, 4)
<font color="#3A3966">    CreateEntity</font>(5,<font color="#3A3966"> MeshID</font>(0),<font color="#3A3966"> MaterialID</font>(1), -2, -2.3, 3)
<font color="#3A3966">    ScaleEntity</font>(5, 8, 0.5, 4)
    
    <font color="#3A3966">; Bodies
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    CreateEntityBody</font>(0, <font color="#924B72">#PB_Entity_StaticBody</font>)
<font color="#3A3966">    CreateEntityBody</font>(1, <font color="#924B72">#PB_Entity_BoxBody</font>, 1.0)
    
<font color="#3A3966">    CreateEntityBody</font>(3, <font color="#924B72">#PB_Entity_SphereBody</font>, 0.5)
    
<font color="#3A3966">    CreateEntityBody</font>(4, <font color="#924B72">#PB_Entity_StaticBody</font>)
<font color="#3A3966">    CreateEntityBody</font>(5, <font color="#924B72">#PB_Entity_BoxBody</font>, 0.1)
    
    <font color="#3A3966">; SliderJoint
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    SliderJoint  </font>(0,<font color="#3A3966"> EntityID</font>(0), -1, 0, 0,<font color="#3A3966"> EntityID</font>(1), 1, 0, 0)
<font color="#3A3966">    SetJointAttribute</font>(0, <font color="#924B72">#PB_SliderJoint_LowerLimit</font>, -3)  
<font color="#3A3966">    SetJointAttribute</font>(0, <font color="#924B72">#PB_SliderJoint_UpperLimit</font>,  0)   
    
    <font color="#3A3966">; HingeJoint
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    HingeJoint</font>(1,<font color="#3A3966"> EntityID</font>(4), 4, 0.1, 2.01, 1, 0, 0,<font color="#3A3966"> EntityID</font>(5), 4, 0.1, -2, 1, 0, 0)
    
    <font color="#3A3966">; Camera
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    CreateCamera</font>(0, 0, 0, 100, 100)
<font color="#3A3966">    MoveCamera</font>(0, 10, 6, 19, <font color="#924B72">#PB_Absolute</font>)
<font color="#3A3966">    CameraLookAt</font>(0, 0, 0, 0)
    
    <font color="#3A3966">; Light
</font><font color="#3A3966">    CreateLight</font>(0, $FFFFFF, 1560, 900, 500)
<font color="#3A3966">    AmbientColor</font>($330000)
    
    <b><font color="#3A3966">Repeat</font></b>
<font color="#3A3966">      Screen3DEvents</font>()
      
       <b><font color="#3A3966">If</font></b> <font color="#3A3966">ElapsedMilliseconds</font>() - Time &gt; 1500 <b><font color="#3A3966">And</font></b> <b><font color="#3A3966">Not</font></b> <font color="#3A3966">DoorClosed</font>() 
         Direction = 1 - Direction
         Time =<font color="#3A3966"> ElapsedMilliseconds</font>()
       <b><font color="#3A3966">EndIf</font></b>

      <b><font color="#3A3966">If</font></b> Direction = 1
<font color="#3A3966">        ApplyEntityImpulse</font>(1, 0.3, 0, 0) 
      <b><font color="#3A3966">Else</font></b>
<font color="#3A3966">        ApplyEntityImpulse</font>(1, -0.3, 0, 0) 
      <b><font color="#3A3966">EndIf</font></b> 
      
      <b><font color="#3A3966">If</font></b> <font color="#3A3966">ExamineMouse</font>()
        MouseX = -<font color="#3A3966">MouseDeltaX</font>() * <font color="#924B72">#CameraSpeed</font> * 0.05
        MouseY = -<font color="#3A3966">MouseDeltaY</font>() * <font color="#924B72">#CameraSpeed</font> * 0.05
      <b><font color="#3A3966">EndIf</font></b>
      
      <b><font color="#3A3966">If</font></b> <font color="#3A3966">ExamineKeyboard</font>()
        
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardReleased</font>(<font color="#924B72">#PB_Key_Space</font>)
          direction = 0
<font color="#3A3966">          DisableEntityBody</font>(1, 0)
<font color="#3A3966">          ApplyEntityImpulse</font>(1, -10, 0, 0) 
          Time =<font color="#3A3966"> ElapsedMilliseconds</font>() 
<font color="#3A3966">          FreeEntity</font>(3)
<font color="#3A3966">          CreateEntity</font>(3,<font color="#3A3966"> MeshID</font>(1),<font color="#3A3966"> MaterialID</font>(3), -1, 15, 0.23)
<font color="#3A3966">          CreateEntityBody</font>(3, <font color="#924B72">#PB_Entity_SphereBody</font>, 0.5)
        <b><font color="#3A3966">EndIf</font></b> 
        
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Left</font>)
          KeyX = -<font color="#924B72">#CameraSpeed</font> 
        <b><font color="#3A3966">ElseIf</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Right</font>)
          KeyX = <font color="#924B72">#CameraSpeed</font> 
        <b><font color="#3A3966">Else</font></b>
          KeyX = 0
        <b><font color="#3A3966">EndIf</font></b>
        
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Up</font>)
          KeyY = -<font color="#924B72">#CameraSpeed</font> 
        <b><font color="#3A3966">ElseIf</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Down</font>)
          KeyY = <font color="#924B72">#CameraSpeed</font> 
        <b><font color="#3A3966">Else</font></b>
          KeyY = 0
        <b><font color="#3A3966">EndIf</font></b>
        
      <b><font color="#3A3966">EndIf</font></b>
      
<font color="#3A3966">      RotateCamera</font>(0, MouseY, MouseX, 0, <font color="#924B72">#PB_Relative</font>)
<font color="#3A3966">      MoveCamera  </font>(0, KeyX, 0, KeyY)
      
<font color="#3A3966">      RenderWorld</font>()
<font color="#3A3966">      Screen3DStats</font>()
<font color="#3A3966">      FlipBuffers</font>()
    <b><font color="#3A3966">Until</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Escape</font>) <b><font color="#3A3966">Or</font></b> Quit = 1
  <b><font color="#3A3966">EndIf</font></b>
  
<b><font color="#3A3966">Else</font></b>
<font color="#3A3966">  MessageRequester</font>(&quot;Error&quot;, &quot;The 3D Engine can't be initialized&quot;,0)
<b><font color="#3A3966">EndIf</font></b>

<b><font color="#3A3966">End</font></b>
</font></pre>
</body></html>
